﻿@model IEnumerable<Bidder>

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "ข้อมูล ผู้ขาย [BD]";
    ViewBag.Descr = "ข้อมูล ผู้ขาย";

    int? intBidId = ViewBag.BidId;
    int? intPrId = ViewBag.PrId;
}

@using (Html.BeginForm("DeleteAll", "Bidder", FormMethod.Post ,new { id="form" }))
{
    @Html.AntiForgeryToken()
    
    <div class="row-fluid">    
       <p id="message"></p>
        <div class="block-button-menu-above">
            @if (ViewBag.bEditable)
            {
                @Html.ActionLink("เพิ่ม", "Create", new { BidId = intBidId, PrId = intPrId }
                , new { @class="btn btn-small btn-success button-standard-width", role="button" })
                
                 @Html.ButtonDeleteAll()

            }
            
            <div class="alert-danger">
                <div class="container-fluid">
                    <br />
                    <b>วิธีใช้งาน</b><br />
                    - เพิ่มผู้ขายที่ต้องการให้ระบบส่งข้อมูลรายการที่ต้องการซื้อ/จ้าง ระบบจะทำการส่งข้อมูลให้เฉพาะผู้ขายที่เลือกเท่านั้น<br />
                    - หากไม่เลือกผู้ขาย ระบบจะทำการส่งข้อมูลรายการที่ต้องการซื้อ/จ้างให้ผู้ขายทุกคนในระบบ Gateway เห็น
                    <hr style="border-top: solid #ca6a5a 1px; border-bottom: none" />
                    <a id="ToGateway" href="#" class="btn button-standard-width btn-small btn-blue icon-file bigger-120" role="button"> ส่งข้อมูลให้ระบบ Gateway</a>
                    @*@Html.ActionLink(" ส่งข้อมูลให้ระบบ Gateway", "ToGateway", new { id = intPrId ?? 0 }, new { @class = "btn button-standard-width btn-small btn-blue icon-file bigger-120", role = "button", id = "ToGateway" })*@
                    <br /><br />
                </div>
            </div>
                
        </div>

        @*<div class="alert-danger">
            
        </div>*@

        <div class = "alert-error">@Html.ValidationSummary()</div>

        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
					@ViewBag.Title
                </div>
				@Html.Partial("_ExportButton")
            </div>
        </div>

        <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
            <thead>
                <tr>
                    <th class="center" style="width:50px;">
						<!-- Check box delete multiple records column-->
                        <label>
                            <input type="checkbox"/>
                            <span class="lbl"></span>
                        </label>
                    </th>
                    <th >
                        ชื่อผู้ขาย
                    </th>
                    <th>

                    </th>
                    @if (intBidId != null)
                    {
                        <th>
                            ซื้อซอง
                        </th>
                        <th>
                            ยื่นซอง
                        </th>
                        <th>
                            ผลการคัดเลือก
                        </th>
                    }
					<th class="center" style="width:80px;">
						<!-- Empty head column for export buttons -->&nbsp;
					</th>
                </tr>
            </thead>

            <tbody>
                @foreach (var m in (IEnumerable<Bidder>) (Model ?? new List<Bidder>()))
                {
                    <tr>
                        
                        <td class="center">
                            <!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.BidderId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>

                        <td>
                            @Html.ActionLink(@m.MasContact.NameTh, "Details", new { Id = m.BidderId })
                        </td>
                        <td>
                            เสนอราคาผ่านระบบ Gateway
                        </td>

                        @if (intBidId != null)
                        {
                            <td>
                                @m.ReceiveStatusName()
                            </td>
                            <td>
                                @m.OfferStatusName()
                            </td>
                            <td>
                                <span class="@(m.WinnerStatus == "1" ? "green" : "")">
                                    @m.WinnerStatusName()
                                </span>
                            </td>
                        }
                        <td class="td-actions">
                            @{if (ViewBag.bEditable)
                              {
                                  @Html.Partial("_ButtonMenuEachRow", new ExportGrid
                                  {
                                      Id = m.BidderId,
                                      DetailsUrl = Url.Action("Details") + "/" + m.BidderId,
                                      EditUrl = Url.Action("Edit") + "/" + m.BidderId,
                                      DeleteUrl = Url.Action("Delete", "Bidder", new { id = m.BidderId })
                                  })

                                 @*@Html.ButtonDelete(, new { Id = m.BidderId }, true)*@
                              }
                              else
                              {
                                  @Html.Partial("_ButtonMenuEachRow", new ExportGrid
                                  {
                                      Id = m.BidderId,
                                      DetailsUrl = Url.Action("Details") + "/" + m.BidderId
                                  })
                              }
                            }
                            @Html.ActionLink(" Reject", "ReportPurchaseRequest", new { id = m.BidderId }, new { @class = "btn btn-mini btn-grey", role = "button" })
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@section scripts {
    
	<script type="text/javascript">
		$(function () {
			var oTable1 = $('#table').dataTable({
				@*/*"aoColumns": [
                    { "bSortable": false },
                    null,
                    @if (intBidId != null)
                    {
                        Html.Raw("null, null, null,");
                    }
                    { "bSortable": false }
				]*/*@
			});

			$('table th input:checkbox').on('click', function () {
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});

			});

			$('[data-rel=tooltip]').tooltip();

			$("#ToGateway").click(function () {
			    var currentForm = this;
			    bootbox.confirm(function (result) {
			        var _result = result;
			        if (result) {
			            $.ajax({
			                url: '@(Url.Action("ToGateway", "Bidder"))?id=' + @intPrId,
			                //type: "post",
			                //dataType: "json",
			                //data: $(currentForm).serialize(),
			                success: function (result) {
			                    if (result.success) {
			                        $("#message").html(result.message);
			                        location.reload();
			                    }
			                    else {
			                        $("#message").html(result.message);
			                    }
			                }
			            });
			        }
			    })
			    return false;
			});

			$("form").submit(function () {
				var currentForm = this;
				bootbox.confirm(function (result) {
					var _result = result;
					if (result) {
						$.ajax({
							url: '@(Url.Action("DeleteAll", "Bidder"))',
							type: "post",
							dataType: "json",
							data: $(currentForm).serialize(),
							success: function (result) {
							    if (result.success) {
							        $("#message").html(result.message);
									location.reload();
								}
							    else {
							        $("#message").html(result.message);
								}
							}
						});
					}
				})
				return false;
			});
		})

	</script>

}